﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using Microsoft.Windows.Design.PropertyEditing;

namespace DenisVuyka.Controls.PropertyGrid
{
  public static class PropertyHelper
  {
    //public static readonly Type[] EnumTypes = 
    //{ 
    //  typeof(Cursor),
    //  typeof(FontWeight),
    //  typeof(FontStretch),
    //  typeof(FontStyle)
    //};

    public static readonly Type[] CultureInvariantTypes = new Type[] 
      { 
        typeof(CornerRadius), 
        typeof(Point3D), 
        typeof(Point4D), 
        typeof(Point3DCollection), 
        typeof(Matrix3D), 
        typeof(Quaternion), 
        typeof(Rect3D), 
        typeof(Size3D), 
        typeof(Vector3D), 
        typeof(Vector3DCollection), 
        typeof(PointCollection), 
        typeof(VectorCollection), 
        typeof(Point), 
        typeof(Rect), 
        typeof(Size), 
        typeof(Thickness), 
        typeof(Vector)     
      };

    public static readonly string[] StringConverterMembers = 
    { 
      "Content", 
      "Header", 
      "ToolTip", 
      "Tag" 
    };
    
    public static PropertyValueEditor GetValueEditor(IEnumerable attributes)
    {
      if (attributes != null)
      {
        foreach (Attribute attribute in attributes)
        {
          EditorAttribute attribute2 = attribute as EditorAttribute;
          if (attribute2 != null)
          {
            try
            {
              Type c = Type.GetType(attribute2.EditorTypeName);
              if ((c == null) || !typeof(PropertyValueEditor).IsAssignableFrom(c))
                continue;

              return (PropertyValueEditor)Activator.CreateInstance(c);
            }
            catch
            {
              continue;
            }
          }
        }
      }
      return null;
    }
  }
}